<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        // const res = axios({
        //     url : `http://ajax-api.itheima.net/api/news`
        // }).then()
        // .catch()
        // console.log(res)
        const p = new Promise(function (resolve, reject) {
            // 1.实例化异步对象
            const xhr = new XMLHttpRequest()
            xhr.open('post', 'http://ajax-api.itheima.net/api/login')
            xhr.setRequestHeader('content-type', 'application/json')
            xhr.addEventListener('load', function () {
                // console.log(JSON.parse(xhr.response))
                // resolve(JSON.parse(xhr.response))
                reject('失败了22')
            })
            let obj = {
                username: 'admin',
                password: '1234567',
            }
            // console.log(JSON.stringify(obj))
            xhr.send(JSON.stringify(obj))

            // reject('失败了22')
        }).then(res => {
            console.log('res', res)
        }).catch(err => {
            console.log('err', err)
        })
    </script>
</body>

</html>